﻿using SourceMaster.Util;
using SourceMaster.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SourceMaster.UserControls
{
    /// <summary>
    /// ChangeSetHistory.xaml 的交互逻辑
    /// </summary>
    public partial class ChangeSetHistory : UserControl
    {
        public ChangeSetHistory()
        {
            InitializeComponent();
        }

        public void RedrawGraph()
        {
            var changesetGraph = new ChangeSetGraph((RepoViewModel)DataContext, Graph);
            changesetGraph.Draw(ChangesetHistoryGrid.Items);

            Graph.Height = changesetGraph.TotalHeight;
        }

        private void ChangesetHistoryGrid_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            var scollerViewer = UIHelper.FindChild<ScrollViewer>(this, "GraphScrollViewer");
            scollerViewer.ScrollToVerticalOffset(Math.Floor(e.VerticalOffset) * 24);

            var dataGrid = UIHelper.FindChild<DataGrid>(this, "ChangesetHistoryGrid");
            scollerViewer.Height = Math.Abs(dataGrid.ActualHeight - 24);
        }
    }

   
}
